package com.lzh.chatnote.chat.service.impl;

import com.lzh.chatnote.chat.dao.RoomDao;
import com.lzh.chatnote.chat.dao.RoomGroupDao;
import com.lzh.chatnote.chat.domain.entity.Room;
import com.lzh.chatnote.chat.domain.entity.RoomGroup;
import com.lzh.chatnote.chat.domain.vo.response.contact.ChatRoomResp;
import com.lzh.chatnote.chat.service.ContactService;
import com.lzh.chatnote.common.domian.vo.request.CursorPageBaseReq;
import com.lzh.chatnote.common.domian.vo.response.CursorPageBaseResp;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Collections;
import java.util.Objects;

@Service
public class ContactServiceImpl implements ContactService {

    @Resource
    private RoomDao roomDao;
    @Resource
    private RoomGroupDao roomGroupDao;


    @Override
    public CursorPageBaseResp<ChatRoomResp> queryCursorPage(CursorPageBaseReq cursorPageBaseReq) {

       Room room = roomDao.queryAllRoom();
       if (Objects.isNull( room)){
           return CursorPageBaseResp.buildEmpty();
       }

       RoomGroup roomGroup = roomGroupDao.queryById(room.getId());
        ChatRoomResp build = ChatRoomResp.builder()
                .id(room.getId())
                .roomName(roomGroup.getName())
                .roomAvatar(roomGroup.getAvatar())
                .roomType(room.getType())
                .hotFlag(room.getHotFlag())
                .activeTime(LocalDateTime.now())
                .text("最后一条消息")
                .unreadCount(0)
                .build();

        return CursorPageBaseResp.buildVO(CursorPageBaseResp.builder()
                        .isLast( true)
                .build(), Collections.singletonList(build));
    }
}
